﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;


namespace GUI_CLock
{
    class Hand
    {
        //Set A set way of defineing what each hand is.
        enum clockHand : int { HOUR, MINUTE, SECOND };

        //Sets the Center of the clock arms
        Point center;

        //Sets where the hand is pointing
        Point edge;

        //Determines which type hand it is. (hour, minute, second)
        clockHand handType;

        //Determines the size of the clock face
        float radius;

        //Hand Colors


        //Constructor accepting center as int values
        public Hand(int x, int y, int handType, float radius, DateTime dateTime)
        {
            center.X = x;
            center.Y = y;
            setHandType(handType);
            this.radius = radius;
            setTime(dateTime);
        }

        //Constructor accepting center as a point
        public Hand(Point center, int handType, float radius, DateTime dateTime)
        {
            this.center = center;
            setHandType(handType);
            this.radius = radius;
            setTime(dateTime);
        }

        private void setHandType(int handInt)
        {
            if (handInt == 0)
            {
                handType = clockHand.HOUR;
            }
            else if (handInt == 1)
            {
                handType = clockHand.MINUTE;
            }
            else if (handInt == 2)
            {
                handType = clockHand.SECOND;
            }
            else
            {
                handType = clockHand.HOUR;
            }
        }

        private void setRadius(float radius)
        {
                this.radius = radius;
        }

        public Line setTime(DateTime dateTime)
        {

            if (handType == clockHand.HOUR)
            {
                float hour = dateTime.Hour % 12 + (float)dateTime.Minute / 60; // also converts 24hrs to 12hrs format
                double hourRadian = (hour * 360) / 12 * Math.PI / 180;//Converst the time value to radians
                hourRadian = hourRadian - (Math.PI / 2);//rotates 90 degrees Counter Clockwise
                edge.X = ((3 * radius)/5 ) * Math.Cos(hourRadian);
                edge.Y = ((3 * radius)/5 ) * Math.Sin(hourRadian);
            }
            else if (handType == clockHand.MINUTE)
            {
                float minute = dateTime.Minute;
                double minRadian = (minute * 360) / 60 * Math.PI / 180;//Converst the time value to radians
                minRadian = minRadian - (Math.PI / 2);//rotates 90 degrees Counter Clockwise
                edge.X = ((5 * radius) / 6) * Math.Cos(minRadian);
                edge.Y = ((5 * radius) / 6) * Math.Sin(minRadian);
            }
            else if (handType == clockHand.SECOND)
            {
                float sec = dateTime.Second;
                double secRadian = (sec * 360) / 60 * Math.PI / 180;//Converst the time value to radians
                secRadian = secRadian - (Math.PI / 2); //rotates 90 degrees Counter Clockwise
                edge.X = radius * Math.Cos(secRadian);
                edge.Y = radius * Math.Sin(secRadian);
            }
            else
            {
                float hour = dateTime.Hour % 12 + (float)dateTime.Minute / 60; // also converts 24hrs to 12hrs format
                double hourRadian = (hour * 360) / 12 * Math.PI / 180;//Converst the time value to radians
                hourRadian = hourRadian - (Math.PI / 2);//rotates 90 degrees Counter Clockwise
                edge.X = radius * Math.Cos(hourRadian);
                edge.Y = radius * Math.Sin(hourRadian);
            }

            edge.X = edge.X + center.X;
            edge.Y = edge.Y + center.Y;

            return setLine(center, edge);
        }

        private Line setLine(Point c, Point e)
        {
            return setLine(c.X, c.Y, e.X, e.Y);
        }

        private Line setLine(double cX, double cY, double eX, double eY)
        {
            Line temp = new Line();

            temp.X1 = cX;
            temp.Y1 = cY;
            temp.X2 = eX;
            temp.Y2 = eY;

            if (handType == clockHand.MINUTE)
            {
                temp.Stroke = System.Windows.Media.Brushes.Blue;
            }
            else if (handType == clockHand.SECOND)
            {
                temp.Stroke = System.Windows.Media.Brushes.Green;
            }
            else
            {
                temp.Stroke = System.Windows.Media.Brushes.Red;
            }
            temp.VerticalAlignment = VerticalAlignment.Center;
            temp.StrokeThickness = 2;

            return temp;
        }


    }
}
